<?php
function request($url, $method = 'GET', $post_data = '', $timeout = 4){
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
    curl_setopt($ch, CURLOPT_HEADER, false);
    if($method == 'POST'){
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
    }

    $response = curl_exec($ch);
    if($response === false){
        $err = curl_error($ch);
        $code = curl_errno($ch);
    }
    curl_close($ch);

    return $response;
}